<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%brand}}".
 *
 * @property integer $id
 * @property string $name
 * @property string $logo
 * @property string $desc
 * @property string $site
 * @property string $sort_order
 */
class Brand extends \common\models\AR {
    public $modelName='品牌';
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return '{{%brand}}';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['name'], 'required'],
            [['desc'], 'string'],
            [['sort_order'], 'integer'],
            [['sort_order'], 'default','value'=>0],
            [['name'], 'string', 'max' => 45],
            [['logo'], 'safe'],
            [['logo'], 'file', 'extensions' => 'jpg, gif, png'],
            [['site'], 'string', 'max' => 200]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'name' => '名称',
            'logo' => 'LOGO图片',
            'desc' => '品牌简述',
            'site' => '网址',
            'sort_order' => '排序',
        ];
    }

    public function afterDelete() {
        parent::afterDelete();

        if (!empty($this->logo)) {
            $path = Yii::getAlias('@img') . '/' . $this->logo;
            @unlink($path);
        }
    }

}
